package com.zxt.controller;

import com.zxt.pojo.Result;
import com.zxt.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.UUID;

@RestController
@Slf4j
public class EmpUploadController {
    //    @PostMapping("/upload")
//    public Result upload(String name, Integer age, MultipartFile file) throws IOException {
//        log.info("{},{},{}",name,age,file);
//        String originalFilename = file.getOriginalFilename();
//
//        if (originalFilename != null) {
//            String houZhui=originalFilename.substring(originalFilename.lastIndexOf("."));
//            String uuid= UUID.randomUUID() .toString()+houZhui;
//            file.transferTo(new File("D:/develop/javaweb/web-ai-code/web-02/tails/src/main/resources/static/images/"+ uuid));
//        }
//
//
//        return Result.success();
//    }
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
         log.info( "文件上传：{}",file.getOriginalFilename());
         //将文件交给阿里云oss管理
        String url = aliyunOSSOperator.upload(file.getBytes(), Objects.requireNonNull(file.getOriginalFilename()));
        log.info("文件上传成功：{}",url);
        return Result.success(url);

    }


}
